<script setup>
import { ref, computed } from 'vue'

const goodsList = ref([
  {
    id: 1,
    name: '月饼',
    state: true
  },
  { id: 2, name: '糖果', state: true }
])
const allSelect = computed({
  get () {
    return goodsList.value.every(item => item.state)
  },
  set (value) {
    return goodsList.value.forEach(item => (item.state = value))
  }
})
</script>

<template>
  <div>
    <p v-for="item in goodsList" :key="item.id">
      <input type="checkbox" v-model="item.state" />
      {{ item.name }}
    </p>
    <p><input type="checkbox" v-model="allSelect" />全选</p>
  </div>
</template>
